<!DOCTYPE HTML>
<html>
<head>
<title>StrLen() / StringLen | AutoHotkey</title>
<meta name="description" content="The StrLen function and StringLen command retrieve the count of how many characters are in a string." />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>StrLen() / StringLen</h1>

<p>获取字符串中包含的字符数量.</p>

<h2 id="function">StrLen()</h2>

<pre class="Syntax">Length := <span class="func">StrLen</span>(String)</pre>
<h3>参数</h3>
<dl>

  <dt>String</dt>
  <dd><p>要统计的字符串.</p></dd>

</dl>

<h3>返回值</h3>
<p>函数返回字符串的长度.</p>

<h3>示例</h3>
 <pre class="NoIndent">InputVar := "The Quick Brown Fox Jumps Over the Lazy Dog"
MsgBox % &quot;The length of InputVar is &quot; . StrLen(InputVar) <em>; 结果为: 43</em></pre>

<h2 id="command">StringLen</h2>
<p class="warning"><strong>不推荐:</strong> 不推荐在新脚本中使用此命令. 使用 <a href="#function">StrLen</a> 函数作为代替.</p>

<pre class="Syntax"><span class="func">StringLen</span>, OutputVar, InputVar</pre>
<h3>参数</h3>
<dl>

  <dt>OutputVar</dt>
  <dd><p>用来存储字符串长度的变量名.</p></dd>

  <dt>InputVar</dt>
  <dd><p>需要统计长度的变量名. 不要把名称括在百分号中, 除非您希望使用变量的 <em>内容</em> 作为被解析的变量名.</p>
</dd>

</dl>

<h3>示例</h3>
<pre class="NoIndent">InputVar := "The Quick Brown Fox Jumps Over the Lazy Dog"
StringLen, Length, InputVar
MsgBox, The length of InputVar is %Length%.</pre>

<h2>备注</h2>
<p>如果 <em>String</em> 或 <em>InputVar</em> 是由 <a href="../misc/Clipboard.htm#ClipboardAll">ClipboardAll</a> 之前所赋值的变量, 那么 StringLen 或 StrLen 将报告其总大小.</p>
<h2>相关</h2>
<p><a href="IfInString.htm">IfInString</a>, <a href="StringGetPos.htm">StringGetPos</a>, <a href="StringMid.htm">StringMid</a>, <a href="StringTrimLeft.htm">StringTrimLeft</a>, <a href="StringTrimLeft.htm">StringTrimRight</a>, <a href="StringLeft.htm">StringLeft</a>, <a href="StringLeft.htm">StringRight</a>, <a href="StringLower.htm">StringLower</a>, <a href="StringLower.htm">StringUpper</a>, <a href="StringReplace.htm">StringReplace</a></p>

</body>
</html>